Conditions | 1 |
Paths | 1 |
Total Lines | 75 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var assert = require('chai').assert, |
||
4 | describe('Document', function(){ |
||
5 | |||
6 | it('Create plain', function(){ |
||
7 | assert.instanceOf(GedcomX.Document(), GedcomX.Document, 'An instance of Document is not returned when calling the constructor with new.'); |
||
8 | assert.instanceOf(GedcomX.Document(), GedcomX.Document, 'An instance of Document is not returned when calling the constructor without new.'); |
||
9 | }); |
||
10 | |||
11 | it('Create with JSON', function(){ |
||
12 | var doc = GedcomX.Document({ |
||
13 | type: 'http://gedcomx.org/Abstract', |
||
14 | extracted: false, |
||
15 | textType: 'plain', |
||
16 | text: 'Lots of text', |
||
17 | attribution: { |
||
18 | created: 123456789 |
||
19 | } |
||
20 | }); |
||
21 | assert.equal(doc.getType(), 'http://gedcomx.org/Abstract'); |
||
22 | assert.equal(doc.getExtracted(), false); |
||
23 | assert.equal(doc.getTextType(), 'plain'); |
||
24 | assert.equal(doc.getText(), 'Lots of text'); |
||
25 | assert.equal(doc.getAttribution().getCreated().getTime(), 123456789); |
||
26 | }); |
||
27 | |||
28 | it('Create with mixed data', function(){ |
||
29 | var doc = GedcomX.Document({ |
||
30 | type: 'http://gedcomx.org/Abstract', |
||
31 | extracted: false, |
||
32 | textType: 'plain', |
||
33 | text: 'Lots of text', |
||
34 | attribution: GedcomX.Attribution({ |
||
35 | created: 123456789 |
||
36 | }) |
||
37 | }); |
||
38 | assert.equal(doc.getType(), 'http://gedcomx.org/Abstract'); |
||
39 | assert.equal(doc.getExtracted(), false); |
||
40 | assert.equal(doc.getTextType(), 'plain'); |
||
41 | assert.equal(doc.getText(), 'Lots of text'); |
||
42 | assert.equal(doc.getAttribution().getCreated().getTime(), 123456789); |
||
43 | }); |
||
44 | |||
45 | it('Build', function(){ |
||
46 | var doc = GedcomX.Document() |
||
47 | .setType('http://gedcomx.org/Abstract') |
||
48 | .setExtracted(false) |
||
49 | .setTextType('plain') |
||
50 | .setText('Lots of text') |
||
51 | .setAttribution(GedcomX.Attribution().setCreated(123456789)); |
||
52 | assert.equal(doc.getType(), 'http://gedcomx.org/Abstract'); |
||
53 | assert.equal(doc.getExtracted(), false); |
||
54 | assert.equal(doc.getTextType(), 'plain'); |
||
55 | assert.equal(doc.getText(), 'Lots of text'); |
||
56 | assert.equal(doc.getAttribution().getCreated().getTime(), 123456789); |
||
57 | }); |
||
58 | |||
59 | it('toJSON', function(){ |
||
60 | var data = { |
||
61 | type: 'http://gedcomx.org/Abstract', |
||
62 | extracted: false, |
||
63 | textType: 'plain', |
||
64 | text: 'Lots of text', |
||
65 | attribution: { |
||
66 | created: 123456789 |
||
67 | } |
||
68 | }, doc = GedcomX.Document(data); |
||
69 | assert.deepEqual(doc.toJSON(), data); |
||
70 | }); |
||
71 | |||
72 | it('constructor does not copy instances', function(){ |
||
73 | var obj1 = GedcomX.Document(); |
||
74 | var obj2 = GedcomX.Document(obj1); |
||
75 | assert.strictEqual(obj1, obj2); |
||
76 | }); |
||
77 | |||
78 | }); |